package com.neusoft.NursingHome.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.neusoft.NursingHome.po.NursingProject;
import com.neusoft.NursingHome.po.ResponseBean;
import com.neusoft.NursingHome.service.NursingProjectService;

@RestController
@RequestMapping("/nursingproject")
public class NursingProjectController {

    @Autowired
    private NursingProjectService nursingProjectService;

    /**
     * 查询所有的护理项目
     * @return 包含所有护理项目列表的 ResponseBean
     */
    @GetMapping("/all")
    public ResponseBean<List<NursingProject>> getAllNursingProjects() {
        List<NursingProject> projects = nursingProjectService.getAllNursingProjects();
        return new ResponseBean<>(projects);
    }

    /**
     * 添加新的护理项目
     * @param nursingProject 护理项目对象
     * @return 添加结果的 ResponseBean
     */
    @PostMapping("/add")
    public ResponseBean<Boolean> addNursingProject(@RequestBody NursingProject nursingProject) {
        boolean result = nursingProjectService.addNursingProject(nursingProject);
        return new ResponseBean<>(result);
    }

    /**
     * 更新护理项目信息
     * @param nursingProject 更新后的护理项目对象
     * @return 更新结果的 ResponseBean
     */
    @PutMapping("/update")
    public ResponseBean<Boolean> updateNursingProject(@RequestBody NursingProject nursingProject) {
        boolean result = nursingProjectService.updateNursingProject(nursingProject);
        return new ResponseBean<>(result);
    }

    /**
     * 获取单个护理项目的详细信息
     * @param projectId 护理项目的唯一标识符
     * @return 包含护理项目详细信息的 ResponseBean
     */
    @GetMapping("/{projectId}")
    public ResponseBean<NursingProject> getNursingProjectById(@PathVariable Integer projectId) {
        NursingProject project = nursingProjectService.getNursingProjectById(projectId);
        return new ResponseBean<>(project);
    }

    /**
     * 逻辑删除护理项目
     * @param projectId 护理项目的唯一标识符
     * @return 删除结果的 ResponseBean
     */
    @DeleteMapping("/delete/{projectId}")
    public ResponseBean<Boolean> deleteNursingProject(@PathVariable Integer projectId) {
        boolean result = nursingProjectService.deleteNursingProject(projectId);
        return new ResponseBean<>(result);
    }

    /**
     * 根据状态查询护理项目
     * @param status 状态值
     * @return 包含符合条件的护理项目列表的 ResponseBean
     */
    @GetMapping("/status/{status}")
    public ResponseBean<List<NursingProject>> getNursingProjectsByStatus(@PathVariable Integer status) {
        List<NursingProject> projects = nursingProjectService.getNursingProjectsByStatus(status);
        return new ResponseBean<>(projects);
    }

    /**
     * 通过护理项目名称模糊查询
     * @param name 护理项目名称（支持模糊匹配）
     * @return 包含匹配的护理项目列表的 ResponseBean
     */
    @GetMapping("/searchByName/{name}")
    public ResponseBean<List<NursingProject>> searchNursingProjectsByName(@PathVariable String name) {
        List<NursingProject> projects = nursingProjectService.searchNursingProjectsByName(name);
        return new ResponseBean<>(projects);
    }
}